package com.bosssoft.cloud.wechat.infrastructure.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author wcy create on 2021/7/27 10:41 上午
 */

@WebFilter(urlPatterns = "/eips/*", filterName = "eipsCommonFilter")
public class EipsCommonFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        HttpServletResponse httpResponse = (HttpServletResponse) response;
//        httpResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // 支持HTTP 1.1.
//        httpResponse.setHeader("Pragma", "no-cache"); // 支持HTTP 1.0. response.setHeader("Expires", "0");
        httpResponse.setHeader("Access-Control-Allow-Origin", "*");//设置允许跨域的域名，需要发送cookie信息，所以此处需要指定具体的域名，
        httpResponse.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, x-access-token");
        //允许跨域的请求方式，理论上只需处理OPTIONS即可
        httpResponse.setHeader("Access-Control-Allow-Methods", "GET, PUT, DELETE, POST, OPTIONS");
        httpResponse.setHeader("Access-Control-Allow-Credentials", "true");//允许发送Cookie信息
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
        // TODO Auto-generated method stub
    }
}
